package com.service.impl;

import com.google.code.shardbatis.strategy.ShardStrategy;
import com.model.ShardTestBean;

/**
 * 
 * Function:分库策略实现 
 * 
 * Project Name:DepotsTableDemo 
 * Package Name:com.service.impl 
 * File Name:ShardStrategyImpl.java 
 * ClassName: ShardStrategyImpl  
 * 
 * @author tankaichao 
 * @email cgztkc@126.com 
 * @Date 2017年1月5日下午4:49:49
 * @since JDK 1.8 
 *
 */
public class ShardStrategyImpl implements ShardStrategy {
	/**
	 * 得到实际表名
	 * 
	 * @param baseTableName 逻辑表名,一般是没有前缀或者是后缀的表名
	 * @param params 		mybatis执行某个statement时使用的参数
	 * @param mapperId 		mybatis配置的statement id
	 * @return
	 */
	public String getTargetTableName(String baseTableName, Object params, String mapperId) {
		Integer k = 0;
		if (params != null) {
			ShardTestBean shardTestBean = (ShardTestBean) params;
			Integer temp = shardTestBean.getAge();
			k = temp % 2;
		}
		return baseTableName + "_" + k;
	}
}
